<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color: pink;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            margin: 0;
            overflow-x: hidden;
        }

        h1 {
            margin: 10px;
        }

        .box {
            background-color: skyblue;
            color: #fff;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 400px;
            height: 200px;
            margin: 10px;
            border-radius: 10px;
            transform: translateX(1000px);
            transition: all 0.3s ease;

        }

        .box:nth-child(even) {
            transform: translateX(-1000px);
            transition: all 0.3s linear;
        }

        .box.show {
            transform: translateX(0);
        }

        .box h2 {
            font-size: 45px;
        }
    </style>
</head>

<body>
    <h1>滑动页面</h1>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>
    <div class="box">
        <h2>textContent</h2>
    </div>

    <script>

        let boxs = document.querySelectorAll(".box");
        fn();

        window.addEventListener("scroll", fn);
        function fn() {
            boxs.forEach((box) => {
                const boxRect = box.getBoundingClientRect();
                if (boxRect.top < window.innerHeight * (3 / 4)) {
                    box.classList.add("show");
                } else {
                    box.classList.remove("show");
                }
            });
        }

    </script>
</body>

</html>